﻿<?php
if(!defined('IN_PHPSCUP'))exit('hacking'); 
class UserApp extends BaseApp
{
    function index()
    {
        if(!isset($_POST['word']))
		{
		$_POST['word'] = '';
		}
        if(!isset($_GET['v']))
		{
		$_GET['v'] = '';
		}			
	    $word = $_POST['word'];
		$word_array = explode(' ',$word);
		
		foreach($word_array as $key => $value)
		{
			if(!$value)
			{
             unset($word_array[$key]);
		    }  
		}
		 
        $order = '';
		$v = $_GET['v'];
		
		$roledata_temp = require($GLOBALS['SCup']->user_power_file);
		
        $roleicon = role_con(ROLE_CON_FILE);
		
		$roledata = array();
		$rolename = array();
		$conditions = '';
		foreach($roledata_temp as $key => $value)
		{
		    $str = '';
			if(isset($value['role_name']))
			{
			     foreach($roleicon as $key1 => $value1)
				 {
				     $str .= $value1.':'.$key.'|';
				 }
			     
				 $roledata[$key]['name'] = $value['role_name'];
				 $roledata[$key]['value'] = substr($str, 0, -1);
				 $rolename[$roledata[$key]['value']] = $value['role_name'];
				 if($v == $roledata[$key]['value'])
				 {
				  $conditions = " role_id='{$v}' ";
				 }
			}
		}
        $this->assign('rolename', $rolename);			
        $this->assign('roledata', $roledata);		
		
		
		
		if($v == 'timeasc')
		{
        $order = 'reg_time asc';
		}
		else if($v == 'timedesc')
		{
        $order = 'reg_time desc';		
		}
		else if($v == 'islocked')
		{
        $order = 'locked desc';		
		}
		
				
	
	    $user = & $GLOBALS['SCup']->_get_user();
	    
		$data = $user->show($order,$v,$word_array,$conditions);		
	
			
        $this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);	



	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		$this->assign('word', $word);
		$this->assign('v', $v);
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('user_list.view.html');
    }

    function post()
    {
		$data = $_POST['data'];
		


	    $user = & $GLOBALS['SCup']->_get_user();
	    
		$user->reg($data);
        $this->index();
    }

    function pedit()
    {
		$data = $_POST['data'];
		


	    $user = & $GLOBALS['SCup']->_get_user();
	    
		$user->edit($data);
        $this->index();
    }


    function del()
    {
	    $id = $_GET['id'];
	    $user = & $GLOBALS['SCup']->_get_user();
	    
		$user->delete($id);	
		  
		$this->index();	  

    }

    function locked()
    {
	
	
	    $id = $_GET['id'];
		$s = $_GET['s'];		
						
	    $user = & $GLOBALS['SCup']->_get_user();

		if(empty($s))
		{						
		 $user->oneedit('locked',$id,1);
		}
		else
		{
		 $user->oneedit('locked',$id,0);		
		}
		
        $this->index();

    }	

    function add()
    {
	    
		$roledata_temp = require($GLOBALS['SCup']->user_power_file);
		
        $roleicon = role_con(ROLE_CON_FILE);
		
		$roledata = array();
		
		foreach($roledata_temp as $key => $value)
		{
		    $str = '';
			if(isset($value['role_name']))
			{
			     foreach($roleicon as $key1 => $value1)
				 {
				     $str .= $value1.':'.$key.'|';
				 }
			     
				 $roledata[$key]['name'] = $value['role_name'];
				 $roledata[$key]['value'] = substr($str, 0, -1);
			}
		}
		
        $this->assign('roledata', $roledata);

	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('user_add.view.html');
    }
 
     function edit()
    {
	    $id = $_GET['id'];
	    $user = & $GLOBALS['SCup']->_get_user();
	    
		$data = $user->get_info($id , 'user_id');
		
				
		$roledata_temp = require($GLOBALS['SCup']->user_power_file);
		
        $roleicon = role_con(ROLE_CON_FILE);
		
		$roledata = array();
		
		foreach($roledata_temp as $key => $value)
		{
		    $str = '';
			if(isset($value['role_name']))
			{
			     foreach($roleicon as $key1 => $value1)
				 {
				     $str .= $value1.':'.$key.'|';
				 }
			     
				 $roledata[$key]['name'] = $value['role_name'];
				 $roledata[$key]['value'] = substr($str, 0, -1);
			}
		}
		
        $this->assign('roledata', $roledata);
        $this->assign('data', $data);
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('user_edit.view.html');
    }
 
 
 
 
 
  
}

    function role_con($str)
    {
	      $array = array();
          $str_array = explode('|',$str);
	      foreach($str_array as $key => $value)
	      {
	            if($value)
		        {
			   
			   $array[$key] = $value;
		   
		        }
	 
	      }    
	   
	      return $array; 		

    }



?>